package xyz.xuminghai.javafx_learn.scene.effect;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.effect.SepiaTone;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

import java.io.FileNotFoundException;
import java.net.URL;

/**
 * 2023/7/6 23:57 星期四<br/>
 * 产生棕褐色调效果的滤镜，类似于古董照片
 *
 * @author xuMingHai
 */
public class SepiaToneApp extends Application {
    private final BorderPane root = new BorderPane();

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void init() throws Exception {
        String fileName = "sepia-tone-app.png";
        URL url = getClass().getResource(fileName);
        if (url == null) {
            throw new FileNotFoundException(fileName);
        }

        Image image = new Image(url.toExternalForm(), 800.0, 600.0, true, true);
        ImageView imageView = new ImageView(image);

        SepiaTone sepiaTone = new SepiaTone();
        imageView.setEffect(sepiaTone);

        root.setCenter(imageView);
    }


    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        Scene scene = new Scene(root, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}
